<template>  
    <div class="wrapper">
        <!--<minibar title="首页" :leftButton="false" :isPadding="true"></minibar>-->
        <list show-scrollbar="false" class="x-list">
            <refresh class="refresh" @refresh="onrefresh" :display="refreshing ? 'show' : 'hide'">
                <loading-indicator class="indicator"></loading-indicator>
            </refresh>
            <cell>
                <x-slider :imageList="banners" :topic="topic"></x-slider>
                <x-palace></x-palace>
                <image class="x-goshop" :src="goshopimg" @click="goShop"></image>
                <image class="x-recd" :src="recdimg"></image>
                <x-imagelist :listData="xpData"></x-imagelist>
                <x-special :listData="soData"></x-special>
                <image class="x-ditu" :src="dituimg"></image>
            </cell>
        </list>
    </div>
</template>

<script>
    import asCore from "../../common/js/core";
    const modal = weex.requireModule('modal');
    const navigator = weex.requireModule('navigator');
    export default {
        components: { 
            "minibar" :require("../../common/component/minbar.vue"),
            "x-slider" :require("./comp/slider.vue"),
            "x-palace" :require("./comp/palace.vue"),
            "x-imagelist":require("./comp/imagelist.vue"),
            "x-special":require("./comp/special.vue"),
        },
        data () {
            return {
                refreshing: false,
                banners: [],
                topic:"-",
                xpData :[],
                soData :{
                    topimage:asCore.localpath + "img/home/tejia.png",
                    data:[]
                },
                goshopimg:asCore.localpath + "img/home/ddyh.png",
                recdimg:asCore.localpath + "img/home/xptj.png",
                dituimg:asCore.localpath + "img/home/ditu.png",
            }
        },
        created() {
            this.loadMainData();
        },
        methods: {
            /*加载首页数据 */
            loadMainData(callback){
                asCore.post("/home",{},(data,msg,flag)=>{
                    if(flag==true){
                       this.topic = data['topic']['title'];
                       /* 轮播图数据 */
                       this.loadCarousel(data['carousel']);
                       this.loadGoods(data['goods_recommend']);
                    }
                    callback && callback();
                });
            },
            /*加载轮播图 */
            loadCarousel(data){
                this.banners = [];
                for(var i in data){
                    this.banners.push({
                        src:data[i]['img']
                    });
                }
            },
            /*加载推荐数据 */
            loadGoods(data){
               // asCore.alert(JSON.stringify(data));
                /* 加载上半的推荐内容 */
                this.xpData = [];
                for(var i=0;i<4;i++){
                    this.xpData.push(data[i]);
                }
                /*加载特价推荐内容 */
                this.soData.data = [];
                for(var i=4;i<8;i++){
                    this.soData.data.push(data[i]);
                }
            },
            onrefresh (event) {
                var _this = this;
                _this.refreshing = true;
                _this.loadMainData(()=>{
                    _this.refreshing = false;
                    modal.toast({
                        message:"刷新成功"
                    });
                });
            },
            goShop(){
                navigator.push(asCore.localpath + 'tailor/index/store.js');
            },
            isIos () {
                const { platform } = weex.config.env;
                return platform.toLowerCase() === 'ios';
            }
        }
    };
</script>
<style scoped src="./css/home.css">
</style>
